package com.itheima.a08Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Random;

public class Test1 {
    public static void main(String[] args) {
        //1.创建集合
        ArrayList<String> list=new ArrayList<>();
        //2.添加元素
        Collections.addAll(list,"张三","李四","王五","赵六","老七","老八","山炮","陈晨","飞扬","土豆");
        //3.生成随机索引
        /*Random r = new Random();
        int index = r.nextInt(list.size());
        String name = list.get(index);
        System.out.println(name);*/

        //第二种随机方法
        Collections.shuffle(list);
        String name1 = list.get(0);
        System.out.println(name1);
    }
}
